package com.dc.refactoring._0_入门;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * Description: 电影类
 * @author: gdc
 * @date: 2020/11/10
 * @version 1.0
 */
@Data
@AllArgsConstructor
@Accessors(chain = true)
public class Movie {
    /**
     * 0:普通片，1：新片，2：儿童
     */
    public static final int REGULAR = 0;
    public static final int NEW_RELEASE = 1;
    public static final int CHILDRENS = 2;

    /**
     * 电影名称
     */
    private String title;
    /**
     * 价格
     */
    private Price price;

    public Movie(String title, int priceCode) {
        this.title = title;
        // 设值函数
        setPriceCode(priceCode);
    }

    public int getPriceCode() {
        return price.getPriceCode();
    }

    public void setPriceCode(int priceCode) {
        switch (priceCode) {
            case REGULAR:
                this.price = new ReleasePrice();
                break;
            case NEW_RELEASE:
                this.price = new NewReleasePrice();
                break;
            case CHILDRENS:
                this.price = new ChildrenPrice();
                break;
            default:
                throw new IllegalArgumentException();
        }
    }

    public double getCharge(int daysRented) {
        return price.getCharge(daysRented);
    }

    public int getFrequentRenterPoints(int daysRented) {
        return price.getFrequentRenterPoints(daysRented);
    }

}
